# Makefile
# Created by tongzhilin on 2020.08.05.

include scripts/rules.mak
USE_DEPEND_A=1

SRC_DIR            = src
EXAMPLES_DIR       = examples

SUBDIRS = $(SRC_DIR)

ifeq ($(WITH_EXAMPLES_DEMO), y)
	SUBDIRS += $(EXAMPLES_DIR)
endif

ifeq ($(USE_DEPEND_A),1)
	COMMON_DIR = src/common/src
	ALG_COMMON_DIR = src/algcommon/src
  ifeq ($(INFERENCE_ENGINE), nnie)
	ALG_BASIC_DIR = src/algbasic_hinnie/src
  else ifeq ($(INFERENCE_ENGINE), mxnet)
	ALG_BASIC_DIR = src/algbasic_mxnet/src
  else ifeq ($(INFERENCE_ENGINE), caffe)
	ALG_BASIC_DIR = src/algbasic_caffe/src
  endif
endif

all: $(SUBDIRS)
	$(PR)mkdir -p $(OUTPUT_LIB_DIR) $(OUTPUT_BIN_DIR) $(OUTPUT_INC_DIR)
  ifeq ($(COMMON_DIR), $(wildcard $(COMMON_DIR)))
	make -j6 -C $(COMMON_DIR) || exit "$$?"
  endif
  ifeq ($(ALG_COMMON_DIR), $(wildcard $(ALG_COMMON_DIR)))
	make -j6 -C $(ALG_COMMON_DIR) || exit "$$?"
  endif
  ifeq ($(ALG_BASIC_DIR), $(wildcard $(ALG_BASIC_DIR)))
	make -j6 -C $(ALG_BASIC_DIR) || exit "$$?"
  endif
	$(PR)for i in ${SUBDIRS} ; do make -C $$i || exit "$$?"; done
config:
	$(PR)$(MAKE) -C scripts/lxdialog all
	/bin/bash scripts/Menuconfig scripts/ipc.in
clean:
  ifeq ($(COMMON_DIR), $(wildcard $(COMMON_DIR)))
	make -C $(COMMON_DIR) clean
  endif
  ifeq ($(ALG_COMMON_DIR), $(wildcard $(ALG_COMMON_DIR)))
	make -C $(ALG_COMMON_DIR) clean
  endif
  ifeq ($(ALG_BASIC_DIR), $(wildcard $(ALG_BASIC_DIR)))
	make -C $(ALG_BASIC_DIR) clean
  endif
	$(PR)for i in ${SUBDIRS} ; do make -C $$i clean ; done
	$(PR)rm -rf scripts/lxdialog/*.o
.PHONY: config clean
